package com.flying.stockdetails.controller;

import com.flying.stockdetails.model.TradingCompany;
import com.flying.stockdetails.repository.TradingCompanyRepository;
import org.springframework.data.util.Streamable;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
public class TradingCompanyController {
    private TradingCompanyRepository repository;

    public TradingCompanyController(TradingCompanyRepository repository) {
        this.repository = repository;
    }

    @GetMapping(value = "/details", produces = {MediaType.APPLICATION_JSON_VALUE})
    public Flux<TradingCompany> getDetails() {
        return repository.findAll();
    }

    @GetMapping(value = "/details/{ticker}", produces = {MediaType.APPLICATION_JSON_VALUE})
    public Mono<TradingCompany> getDetails(@PathVariable("ticker") String ticker) {
//        Streamable<TradingCompany> result = repository.findByTickerContaining("av");
        return repository.findByTicker(ticker);
    }
}
